import time
import os
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import Select

class Drop_down:
    def __init__(self):
        # 打开浏览器
        self.driver = webdriver.Chrome()
        self.driver.maximize_window()
        # 打开本地链接
        self.url = 'file:///' + os.path.abspath('注册实例.html')
        self.driver.get(self.url)
    def pull_down(self):
        # 定位下拉栏
        s1 = self.driver.find_element(By.ID, 'select')
        select = Select(s1)
        # 点击对应的下拉选项
        time.sleep(2)
        # 通过索引选取
        # select.select_by_index(2)
        # 通过value值选取
        # select.select_by_value('sh')
        # 通过文本选取
        select.select_by_visible_text('广州')

    def quit(self):
        time.sleep(2)
        self.driver.quit()


if __name__ == '__main__':
    drop_down = Drop_down()
    drop_down.pull_down()
    drop_down.quit()